'use strict';
	angular.module('inventory.fileItemSelectSingle', [])
	.controller('fileItemSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


		var Model = this;


		Model.gridRowClick = function(event){
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		var options = {};
		options.container = Model;
		options.concept = 'FileItem';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
 		options.reader = '/inventory/fileItem/list/query';
		options.writer = '/inventory/fileItem/list/save';
		options.deleter = '/inventory/fileItem/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.nodeSortRelation = "sortNo";
		options.rootFilter = '';
//		options.pathRelation = 'itemFullID';
		options.limit = 10;
		options.orderBy = "sortNo ASC, itemNo ";
		
		$scope.dataList = new BizData(options);
		
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
        	Model.title = title;  
        	Model.params = params;  
//        	console.log('Model.params-->',Model.params);
//        	console.log('Model.params.batchNo-->',Model.params.batchNo);

    		//设置过滤条件
    		$scope.dataList.filter = "FileItem.enterpriseNo = '"+ Model.params.id +"'"
    		+ " AND FileItem.status='open' "
    		;
    		
    		if(params.configType){
    			var configType = params.configType;
    			$scope.dataList.filter = $scope.dataList.filter + " AND FileItem.configType="+configType;
    		}
    		
    		/*
    		if(params.kind=='nkLeaf'){
    			//只显示叶子
        		$scope.dataList.treeOption.rootFilter = '';
        		$scope.dataList.filter = $scope.dataList.filter + " AND FileItem.nodeKind='nkLeaf'"
        		;
    		}
    		*/
    		
    		//只显示启用批号管理的物料档案
    		if(Model.params.batchNo=='Y'){
    			$scope.dataList.setFilter('batchNoFilter','FileItem.batchNo is null');
    		}
    		
    		//刷新数据
    	    $scope.dataList.refreshData();
        });  
		 

		
        
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataList.rows[$scope.dataList.currentIndex];
	    	var row = {};
			//循环行中的列，取出列的值，装配成简单的行
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////

	    return Model;
	    
	}	
	
